package com.komorebishao.code;

import java.util.HashMap;
import java.util.Map;

public class Code1 {
    public int[] twoSum(int[] nums, int target) {
        if (nums == null || nums.length == 0) {
            throw new IllegalArgumentException("nums == null || nums.length == 0");
        }
        Map<Integer, Integer> matchUtil = new HashMap<>();
        for (int temp : nums) {
            if (matchUtil.containsKey(target - temp)) {
                return new int[] {nums[temp], temp};
            }
            matchUtil.put(temp, nums[temp]);
        }
        throw new IllegalArgumentException("No result found");
    }
}
